package com.soft.springhrms.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        // 创建 MybatisPlusInterceptor 实例
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        // 创建分页插件
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();

        // 设置数据库类型，这里是 MySQL
        paginationInnerInterceptor.setDbType(DbType.MYSQL);

        // 设置分页插件的溢出处理，防止请求页码超过最大页码时，回到首页
        paginationInnerInterceptor.setOverflow(true);

        // 添加分页插件到拦截器中
        interceptor.addInnerInterceptor(paginationInnerInterceptor);

        // 返回 MybatisPlusInterceptor 实例
        return interceptor;
    }
}

